package com.moweilin.hello_server;

import io.vertx.core.Handler;
import io.vertx.core.http.HttpServerRequest;
import io.vertx.core.http.HttpServerResponse;
import io.vertx.core.streams.Pump;
import io.vertx.ext.web.RoutingContext;

/**
 * Created by moweilin on 2016/4/22.
 */
public class HeadHandler implements Handler<RoutingContext>{
    @Override
    public void handle(RoutingContext event) {
        HttpServerResponse response = event.response();
        response.setChunked(true);
        HttpServerRequest request = event.request();
        response.write("<html><body><h3>request header</h3>");
        request.headers().forEach(entry -> {
            response.write(entry.getKey()+ " : " + entry.getValue() +"<br />");
        });
        response.write("<div><h3>request body</h3></div>");
        Pump pump = Pump.pump(request,response);
        request.endHandler(v->{
            response.write("</body></html>");
            response.end();});
        pump.start();

    }


}
